]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Refactor show()/hide() sequences
authorJasper St. Pierre <jstpierre@mecheye.net>
Fri, 16 Mar 2012 22:53:14 +0000 (18:53 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Wed, 2 May 2012 16:43:58 +0000 (12:43 -0400)
We seem to have a lot of code that does something along the lines of:

    if (condition)
        actor.show();
    else
        actor.hide();

ClutterActor already has such a thing for exactly this purpose: the 'visible'
property. Use it instead of the mess above.

https://bugzilla.gnome.org/show_bug.cgi?id=672272

js/gdm/powerMenu.js
js/ui/magnifier.js
js/ui/status/bluetooth.js
js/ui/status/network.js
js/ui/status/volume.js
js/ui/userMenu.js
js/ui/workspacesView.js

index 32edccda43cba2d1ed5df1aa75814322828c38e4..3804ec5685b3e1cc3894c48b6eb2389cda7abd01 100644 (file)
@@ -60,10 +60,8 @@ const PowerMenuButton = new Lang.Class({
     },
 
     _updateVisibility: function() {
-        if (!this._haveSuspend && !this._haveShutdown && !this._haveRestart)
-            this.actor.hide();
-        else
-            this.actor.show();
+        let shouldBeVisible = (this._haveSuspend || this._haveShutdown || this._haveRestart);
+        this.actor.visible = shouldBeVisible;
     },
 
     _updateHaveShutdown: function() {
@@ -76,11 +74,7 @@ const PowerMenuButton = new Lang.Class({
                     else
                         this._haveShutdown = false;
 
-                    if (this._haveShutdown)
-                        this._powerOffItem.actor.show();
-                    else
-                        this._powerOffItem.actor.hide();
-
+                    this._powerOffItem.actor.visible = this._haveShutdown;
                     this._updateVisibility();
                 }));
         } else {
@@ -91,12 +85,7 @@ const PowerMenuButton = new Lang.Class({
                     else
                         this._haveShutdown = false;
 
-                    if (this._haveShutdown) {
-                        this._powerOffItem.actor.show();
-                    } else {
-                        this._powerOffItem.actor.hide();
-                    }
-
+                    this._powerOffItem.actor.visible = this._haveShutdown;
                     this._updateVisibility();
                 }));
         }
@@ -112,11 +101,7 @@ const PowerMenuButton = new Lang.Class({
                     else
                         this._haveRestart = false;
 
-                    if (this._haveRestart)
-                        this._restartItem.actor.show();
-                    else
-                        this._restartItem.actor.hide();
-
+                    this._restartItem.actor.visible = this._haveRestart;
                     this._updateVisibility();
                 }));
         } else {
@@ -127,12 +112,7 @@ const PowerMenuButton = new Lang.Class({
                     else
                         this._haveRestart = false;
 
-                    if (this._haveRestart) {
-                        this._restartItem.actor.show();
-                    } else {
-                        this._restartItem.actor.hide();
-                    }
-
+                    this._restartItem.actor.visible = this._haveRestart;
                     this._updateVisibility();
                 }));
         }
@@ -140,12 +120,7 @@ const PowerMenuButton = new Lang.Class({
 
     _updateHaveSuspend: function() {
         this._haveSuspend = this._upClient.get_can_suspend();
-
-        if (this._haveSuspend)
-            this._suspendItem.actor.show();
-        else
-            this._suspendItem.actor.hide();
-
+        this._suspendItem.actor.visible = this._haveSuspend;
         this._updateVisibility();
     },
 
index b1db9115b3a3ce460f3f246a44bfd52675935fad..7608e0864b05fa644147fd1c35c9f53e6c08a020 100644 (file)
@@ -1228,10 +1228,7 @@ const Crosshairs = new Lang.Class({
                     crosshairsActor = new Clutter.Clone({ source: this._actor });
                     this._clones.push(crosshairsActor);
                 }
-                if (this._actor.visible)
-                    crosshairsActor.show();
-                else
-                    crosshairsActor.hide();
+                crosshairsActor.visible = this._actor.visible;
 
                 container.add_actor(crosshairsActor);
                 container.raise_child(magnifiedMouse, crosshairsActor);
index f6d2f306f63b88825fd8a6b2c487f29a888bb9ce..c671e6b656ea7bfe8fa9e3a5b4c54854a08793b6 100644 (file)
@@ -106,10 +106,7 @@ const Indicator = new Lang.Class({
             /* TRANSLATORS: this means that bluetooth was disabled by hardware rfkill */
             this._killswitch.setStatus(_("hardware disabled"));
 
-        if (has_adapter)
-            this.actor.show();
-        else
-            this.actor.hide();
+        this.actor.visible = has_adapter;
 
         if (on) {
             this._discoverable.actor.show();
index 36249d8a4624d78edc2b1ca0f04c2f05d3673dbf..f1ba1194fcdc72021b118c9950852e4b4693ca1b 100644 (file)
@@ -707,10 +707,7 @@ const NMDeviceWired = new Lang.Class({
         // the device
         // we can do it here because addConnection and removeConnection
         // both call _createSection at some point
-        if (this._connections.length <= 1)
-            this.section.actor.hide();
-        else
-            this.section.actor.show();
+        this.section.actor.visible = this._connections.length <= 1;
     },
 
     _createAutomaticConnection: function() {
@@ -1038,13 +1035,8 @@ const NMDeviceWireless = new Lang.Class({
     },
 
     setEnabled: function(enabled) {
-        if (enabled) {
-            this.statusItem.actor.show();
-            this.section.actor.show();
-        } else {
-            this.statusItem.actor.hide();
-            this.section.actor.hide();
-        }
+        this.statusItem.actor.visible = enabled;
+        this.section.actor.visible = enabled;
     },
 
     activate: function() {
index ff907ca6231e872e8f84bafee543ce25ece6d85c..6951cb167dcac2a676c635139edc817cb9ad2b89 100644 (file)
@@ -149,13 +149,9 @@ const Indicator = new Lang.Class({
                 }
             }
         }
-        if (showInput) {
-            this._inputTitle.actor.show();
-            this._inputSlider.actor.show();
-        } else {
-            this._inputTitle.actor.hide();
-            this._inputSlider.actor.hide();
-        }
+
+        this._inputTitle.actor.visible = showInput;
+        this._inputSlider.actor.visible = showInput;
     },
 
     _volumeToIcon: function(volume) {
index 4894892038e1c4d4cc460e5304d2a951d1039eb7..01b4702a594358313a4091ea0fe0a8934a64663b 100644 (file)
@@ -554,18 +554,12 @@ const UserMenuButton = new Lang.Class({
 
     _updateLogout: function() {
         let allowLogout = !this._lockdownSettings.get_boolean(DISABLE_LOG_OUT_KEY);
-        if (allowLogout)
-            this._logoutItem.actor.show();
-        else
-            this._logoutItem.actor.hide();
+        this._logoutItem.actor.visible = allowLogout;
     },
 
     _updateLockScreen: function() {
         let allowLockScreen = !this._lockdownSettings.get_boolean(DISABLE_LOCK_SCREEN_KEY);
-        if (allowLockScreen)
-            this._lockScreenItem.actor.show();
-        else
-            this._lockScreenItem.actor.hide();
+        this._logoutItem.actor.visible = allowLockScreen;
     },
 
     _updateHaveShutdown: function() {
@@ -584,10 +578,7 @@ const UserMenuButton = new Lang.Class({
         if (!this._suspendOrPowerOffItem)
             return;
 
-        if (!this._haveShutdown && !this._haveSuspend)
-            this._suspendOrPowerOffItem.actor.hide();
-        else
-            this._suspendOrPowerOffItem.actor.show();
+        this._suspendOrPowerOffItem.actor.visible = this._haveShutdown || this._haveSuspend;
 
         // If we can't suspend show Power Off... instead
         // and disable the alt key
index 272aa47f3acc32507cb25900bd4d70214af467e9..e364509f286cf42cd7c87c2f54b371e91447a516 100644 (file)
@@ -844,10 +844,7 @@ const WorkspacesDisplay = new Lang.Class({
                         if (!primaryView)
                             return;
                         primaryView.actor.opacity = opacity;
-                        if (opacity == 0)
-                            primaryView.actor.hide();
-                        else
-                            primaryView.actor.show();
+                        primaryView.actor.visible = opacity != 0;
                     }));
         }));
     },